package sixkey.Exception.handler;

import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import sixkey.Exception.SystemException;
import sixkey.Exception.TestException;
import sixkey.utils.ResponseInfo;

import java.nio.file.AccessDeniedException;

/**
 * ClassName:ExceptionHandlerAdvice
 * Package:sixkey.Exception.handler
 * Description
 *
 * @Author:@wenxueshi
 * @Create:2023/7/12 - 14:36
 * @Version:v1.0
 */
@Slf4j
@RestControllerAdvice
public class ExceptionHandlerAdvice {

    @ExceptionHandler(Exception.class)
    @ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
    public ResponseInfo<String> handleUnexpectedServer(Exception ex) {
        log.error("系统异常：", ex);
        return ResponseInfo.fail("系统发生异常，请联系管理员");
    }

    /**
     * 系统异常处理
     */
    @ExceptionHandler(Throwable.class)
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public ResponseInfo<String> exception(Throwable throwable) {
        log.error("系统异常", throwable);
        return new ResponseInfo<>(HttpStatus.INTERNAL_SERVER_ERROR.value() + "系统测试异常，请联系管理员！");
    }

    @ExceptionHandler(TestException.class)
    public ResponseInfo<String> exception(TestException e){
        return ResponseInfo.fail("测试系统异常4");
    }
}
